package com.fei.fpmall.service.basemanage.impl;

import com.fei.fpmall.core.dto.ResponseModel;
import com.fei.fpmall.core.model.Page;
import com.fei.fpmall.core.utils.Md5Util;
import com.fei.fpmall.dao.basemanage.IUserdetailDao;
import com.fei.fpmall.entity.basemanage.UserdetailEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fei.fpmall.dao.basemanage.IUsersDao;
import com.fei.fpmall.entity.basemanage.User;
import com.fei.fpmall.service.basemanage.IUsersService;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

@Service("usersService")
public class UsersServiceImpl implements IUsersService {
    @Autowired
    private IUsersDao usersDao;

    @Autowired
    private IUserdetailDao userdetailDao;

    @Override
    public User queryObject(Integer uid) {

        User userInfo = usersDao.findById(uid);
        return userInfo;
    }

    @Override
    public List<User> queryList(Map<String, Object> map) {
        return null;
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return 0;
    }

    @Override
    public int save(User userInfo, UserdetailEntity userdetailInfo) {
        //默认值
        Date now=new Date();
        userInfo.setCreatedTime(now);
        userInfo.setModifiedTime(now);
        userInfo.setUserstatus(1);
        userInfo.setPassword(Md5Util.getMD5Code("123456"));
        usersDao.save(userInfo);
        int uid =userInfo.getUid();
        userdetailInfo.setUid(uid);
        userdetailInfo.setLastvisittime(now);
        userdetailInfo.setRegistertime(now);
        userdetailDao.save(userdetailInfo);
        return uid;
    }

    @Override
    public int update(User userInfo) {
        userInfo.setModifiedTime(new Date());
        usersDao.update(userInfo);
        return 0;
    }

    @Override
    public int delete(Integer uid) {
        return 0;
    }

    @Override
    public void deleteBatch(Integer[] uids) {

    }

    @Override
    public User manageLoginbyuserName(User member, HttpServletRequest request) {
        String password = member.getPassword();
        //member.setPassword(Md5Util.getMD5Code(member.getPassword()));        
        return null;
    }

    @Override
    public User manageLoginbyMobile(User member, HttpServletRequest request) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public User manageLoginbyEmail(User member, HttpServletRequest request) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public User queryObjectByCondition(Map condition) {
        User userInfo = usersDao.queryObjectByCondition(condition);
        return userInfo;
    }

    //分页查询用户
    @Override
    public ResponseModel queryListByPage(Map<String, Object> condition, Page page) {
        ResponseModel model = new ResponseModel(0, page);
        List<User> list = usersDao.queryListByPage(page, condition);
        model.setData(list);
        return model;
    }

}
